/******************************************************************************/
/*									INFO					  				  */
/******************************************************************************/
/*

PROJECT
	Article: "Choice and Choice Set in African Elections"
	Author: Karen Ferree

DO FILE
	Purpose: replication files for JOP paper
	Created: By Karen Ferree, July 2021
	This file creates Tables 1 and 2, Figure 1, and Appendix Tables.
	It first generates descriptive statistics for Ghana, then for Kenya, then for Uganda
	Tables created manually by compiling descriptive statistics across cases
*/


/******************************************************************************/
/*							GHANA			            				  */
/******************************************************************************/

/* Load Ghana data */
clear
use "/Users/karenferree/Documents/BOOK/stata work/JOP_replication/Kef_jop_ghana.dta", clear


/* Creating choice set variable legislative level GHANA */
/* create mixed choice set variable (Ashanti level) */

gen co_eth_choice_parl_2008 = 1 if all_co_eth_parl_2008 == 0 & co_eth_parl_2008 == 1
replace co_eth_choice_parl_2008 = 0 if all_co_eth_parl_2008 == 1 | co_eth_parl_2008 == 0
lab var co_eth_choice_parl_2008 "Had a coethnic, non coethnic choice, 0/1"

/* create 3 category choice set variable (Ashanti level) */
gen choice_set = 0 if co_eth_parl_2008 == 0
replace choice_set = 1 if co_eth_choice_parl_2008 == 1
replace choice_set = 2 if all_co_eth_parl_2008 == 1

lab var choice_set "choice set Ashanti level"

label define lable1 0 "no co-ethnic on ballot" 1 "mixed ballot" 2 "only co-ethnics on ballot"
label values choice_set lable1 

/* Generate descriptive tables (Ghana) */
/* Table 1 choice set table for Ghana (Ashanti level)*/
/* Table 1 legislative choice set */
tab choice_set
/* Table 1 presidential choice set */
tab co_eth_prez_2008 

/* Table 2 decomposing ethnic voting for Ghana (Ashanti level)*/

/* Table 2 legislative */
/* co-ethnic voting all voters*/
tabulate vote_co_eth_parl_2008
/* coethnic voting only voters with mixed choice set */  
tabulate vote_co_eth_parl_2008 if co_eth_choice_parl_2008 == 1

/* Table 2 presidential */
/* co-ethnic voting all voters*/
tab vote_co_eth_prez_2008
/* coethnic voting only voters with mixed choice set */
tab vote_co_eth_prez_2008 if co_eth_prez_2008 == 1


/* ****************************************** */
/* AKAN LEVEL refinement */
/* Figure 1 Ghana Ashanti vs. Akan Choice Sets and Appendix A-2 and A-3 Tables*/
/* create continuous choice set (Ashanti level) */
gen pct_coethnic_leg = num_co_eth_parl_2008/num_cand_parl_2008
lab var pct_coethnic_leg "Leg. Choice Set Percent Co-ethnic Ashanti level"

kdensity pct_coethnic_leg, title("Ghana Ashanti Level") xtitle("Percent choice set co-ethnic"), quiet
graph save ghana_legchoiceset_sub.gph, replace

/* create continuous choice set (Akan level) */
/* variable created in candidate ethnicity recode*/

kdensity pct_coethnic_leg_cen, title("Ghana Akan Level") xtitle("Percent choice set co-ethnic"), quiet
graph save ghana_legchoiceset_super.gph, replace

/*Figure 1 here */
graph combine ghana_legchoiceset_sub.gph ghana_legchoiceset_super.gph, ycommon xcommon

/* recalculate 3 category super group for Akan level */

gen choice_set_cen = 0 if co_eth_parl_2008_cen == 0
replace choice_set_cen = 1 if co_eth_choice_parl_2008_cen == 1
replace choice_set_cen = 2 if all_co_eth_parl_2008_cen == 1

lab var choice_set_cen "choice set Akan level"
label values choice_set_cen lable1

/*reproduce Tables 1 for Akan level for appendix Table A1*/
/* legislative AKAN */
tabulate choice_set_cen
/* presidential AKAN */
tabulate co_eth_prez_2008_cen

/* reproduce Table 2 decompose ethnic voting for super group (Akan level) Table A2*/
/* legislative AKAN*/
tabulate vote_co_eth_parl_2008_cen  
tabulate vote_co_eth_parl_2008_cen if co_eth_choice_parl_2008_cen == 1

/* presidential AKAN*/
tab vote_co_eth_prez_2008_cen
tab vote_co_eth_prez_2008_cen if co_eth_prez_2008_cen == 1

/* ************************************************ */
/* APPENDIX top party co-ethnic refinement Table A-3 Appendix*/

/* create variable: has NPP or NDC co-ethnic */
gen NPP_coethnic = 1 if cand_eth_npp_parl_2008 == resp_eth_code
replace NPP_coethnic = 0 if cand_eth_npp_parl_2008 != resp_eth_code
replace NPP_coethnic = . if cand_eth_npp_parl_2008 == . | resp_eth_code ==.

gen NDC_coethnic = 1 if cand_eth_ndc_parl_2008 == resp_eth_code
replace NDC_coethnic = 0 if cand_eth_ndc_parl_2008 != resp_eth_code
replace NDC_coethnic = . if cand_eth_ndc_parl_2008 == . | resp_eth_code ==.

gen NPPorNDC_coethnic = 1 if NPP_coethnic == 1 | NDC_coethnic == 1
replace NPPorNDC_coethnic = 0 if NPP_coethnic == 0 & NDC_coethnic == 0
replace NPPorNDC_coethnic = . if NPP_coethnic == . | NDC_coethnic == .

tabulate NPPorNDC_coethnic
tabulate co_eth_parl_2008

/* note, to calculate "has major party co-ethnic" for Table A-3, divide count of NPPorNDC_coethnic ==1 by total obs in co_eth_parl_2008 */



/******************************************************************************/
/*							Kenya		            				  */
/******************************************************************************/


/* Load Kenya data */
clear
use "/Users/karenferree/Documents/BOOK/stata work/JOP_replication/Kef_jop_kenya.dta", clear


/* Creating choice set variables for Kenya legislative elections */

/* create mixed choice set variable */ 
gen co_eth_choice_parl_2007 = 1 if all_co_eth_parl_2007 == 0 & co_eth_parl_2007 == 1
replace co_eth_choice_parl_2007 = 0 if all_co_eth_parl_2007 == 1 | co_eth_parl_2007 == 0
lab var co_eth_choice_parl_2007 "Had a coethnic, non coethnic choice, 0/1"

/* create 3 category choice set variable */
gen choice_set = 0 if co_eth_parl_2007 == 0
replace choice_set = 1 if co_eth_choice_parl_2007 == 1
replace choice_set = 2 if all_co_eth_parl_2007 == 1

lab var choice_set "choice set"

label define lable1 0 "no co-ethnic on ballot" 1 "mixed ballot" 2 "only co-ethnics on ballot"
label values choice_set lable1 

/* Generate Descriptive tables Kenya */
/* Table 1 choice set table for Kenya*/
/* Table 1 legislative choice set */
tabulate choice_set

/* Table 1 presidential choice set */
tabulate co_eth_prez_2007 

/* Table 2 decomposing ethnic voting for Kenya*/

/* Table 2 legislative */
/* co-ethnic voting all voters*/
tabulate vote_co_eth_parl_2007
/* coethnic voting only voters with mixed choice set */  
tabulate vote_co_eth_parl_2007 if co_eth_choice_parl_2007 == 1

/* Table 2 presidential */
/* co-ethnic voting all voters*/
tabulate vote_co_eth_prez_2007
/* coethnic voting only voters with mixed choice set */
tabulate vote_co_eth_prez_2007 if co_eth_prez_2007 == 1

/* ************************************* */
/* APPENDIX has PNU co-ethnic Table A-3 Refinement*/
/* create variable: has PNU co-ethnic */
gen PNU_coethnic = 1 if cand_eth_pnu_parl_2007 == resp_eth_code
replace PNU_coethnic = 0 if cand_eth_pnu_parl_2007 != resp_eth_code
replace PNU_coethnic = . if cand_eth_pnu_parl_2007 == . | resp_eth_code == .

tabulate PNU_coethnic 
tabulate co_eth_parl_2007
/* note, to calculate "has major party co-ethnic" for Table A-3, divide count of PNU_coethnic ==1 by total obs in co_eth_parl_2007 */

/******************************************************************************/
/*							Uganda	            				  */
/******************************************************************************/


/* Load Uganda data */
clear
use "/Users/karenferree/Documents/BOOK/stata work/JOP_replication/Kef_jop_uganda.dta", clear


/* Create choice set variables for Uganda legislative elections */

/* create mixed choice set variable*/
gen co_eth_choice_parl_2011 = 1 if all_co_eth_parl_2011 == 0 & co_eth_parl_2011 == 1
replace co_eth_choice_parl_2011 = 0 if all_co_eth_parl_2011 == 1 | co_eth_parl_2011 == 0
lab var co_eth_choice_parl_2011 "Had a coethnic, non coethnic choice, 0/1"

/* create 3 category choice set variable*/
gen choice_set = 0 if co_eth_parl_2011 == 0
replace choice_set = 1 if co_eth_choice_parl_2011 == 1
replace choice_set = 2 if all_co_eth_parl_2011 == 1

lab var choice_set "choice set"

label define lable1 0 "no co-ethnic on ballot" 1 "mixed ballot" 2 "only co-ethnics on ballot"
label values choice_set lable1 

/* Generate Descriptive tables Uganda */
/* Table 1 for Uganda */
/* Table 1 legislative choice set */
tabulate choice_set

/* Table 1 presidential choice set */
tabulate co_eth_prez_2011 

/* Table 2 decomposing ethnic voting for Uganda*/

/* Table 2 legislative */
/* co-ethnic voting all voters*/
tabulate vote_co_eth_parl_2011
/* coethnic voting only voters with mixed choice set */  
tabulate vote_co_eth_parl_2011 if co_eth_choice_parl_2011 == 1

/* Table 2 presidential */
/* co-ethnic voting all voters*/
tabulate vote_co_eth_prez_2011
/* coethnic voting only voters with mixed choice set */
tabulate vote_co_eth_prez_2011 if co_eth_prez_2011 == 1

/* ************************************* */
/* APPENDIX has NRM co-ethnic for Table A-3 Refinement*/

/* create has NRM co-ethnic */
gen NRM_coethnic = 1 if cand_eth_nrm_parl_2011 == resp_eth_code
replace NRM_coethnic = 0 if cand_eth_nrm_parl_2011 != resp_eth_code
replace NRM_coethnic = . if cand_eth_nrm_parl_2011 == . | resp_eth_code == .

tabulate NRM_coethnic
tabulate co_eth_parl_2011
/* note, to calculate "has major party co-ethnic" for Table A-3, divide count of NRM_coethnic ==1 by total obs in co_eth_parl_2011 */



